package io.renren.modules.pullin.controller;


import io.renren.modules.jxgk.utils.UUidCreater;
import io.renren.modules.pullin.DataConversion.TeachControlView;
import io.renren.modules.pullin.entity.*;
import io.renren.modules.jxgkphone.entity.StudentInfo;
import io.renren.modules.pullin.service.PullOutService;
import io.renren.modules.pullin.service.PullinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.*;
import java.util.List;

@RestController
@RequestMapping("/Pullin")
public class PullinController {

    @Autowired
    PullinService pullinService;
    @Autowired
    PullOutService pullOutService;
    UUidCreater uuid=new UUidCreater();
    String errReason;
    String errId;
    String errPos;
    String erresult;
    @RequestMapping("/Test")
    public List<BinzhiClassCourse> Test(){
        List<BinzhiClassCourse> binzhiClassCourses=pullinService.CopyClassCourseFromOralce();
        return binzhiClassCourses;
    }
    @RequestMapping(value = "/getClassCourseData")
    public String GetClassCourseData(){
        List<BinzhiClassCourse> binzhiClassCourses=pullinService.CopyTrueClassCourseFO2();
        Iterator it = binzhiClassCourses.iterator();
        int i=1;
        TeachControlView tcv=new TeachControlView();
        while(it.hasNext()) {
            BinzhiClassCourse t= (BinzhiClassCourse) it.next();
            if(t.getSKSJ()!=null){
                try {
                    List<ClassCourse> l=tcv.InformationSet(t.getXKKH(),t.getKCMC(),t.getBJMC(),t.getJSXM(),
                            t.getJSZGH(),"1","2017-2018",t.getSKDD(),t.getSKSJ(),t.getXSXY());
                    for(ClassCourse c:l){
                      //  List<ClassCourse> exist=pullOutService.findClassCourseByClassNameAndCourseId(c.getClass_name(),c.getCourse_school_id());

                            pullOutService.insertClassCourse(c);
                            System.out.println("log:插入数据成功，本条第"+i+"条");
                            i++;

                    }
                }catch (Exception e){
                    errReason="班级课程信息错误原因:"+e+"\n";
                    errId="错误位置:"+i+"\n";
                    errPos="错误信息:"+t.getXKKH()+"\n";
                    erresult=errReason+errId+errPos;
                    tcv.appendMethodB("errInfo.txt",erresult);
                }
            }
        }
        return i+"条数据全部完成";
    }
    @RequestMapping(value = "/getStudentInfoData")
    public String getStudentInfoData(){
        List<BinzhiStudentInfo> si = pullinService.CopyStudentInfoFO2();
        Iterator it = si.iterator();
        int i=0;
        while(it.hasNext()) {
//            BinzhiStudentInfo tempStudent = (BinzhiStudentInfo) it.next();
            StudentInfo studentInfo=new StudentInfo();
//            studentInfo.setStudent_id(uuid.getUUID());
//            studentInfo.setStudent_department(tempStudent.getXY());
//            studentInfo.setStudent_class_name(tempStudent.getXZB());
//            studentInfo.setStudent_school_id(tempStudent.getXH());
//            studentInfo.setStudent_name(tempStudent.getXM());
//            studentInfo.setStudent_sexual(tempStudent.getXB());
//            studentInfo.setStudent_birthday(tempStudent.getCSRQ());
//            studentInfo.setStudent_ethnicity(tempStudent.getMZ());
//            studentInfo.setStudent_profession_name(tempStudent.getZYMC());
//            studentInfo.setStudent_schooling_year(tempStudent.getXZ());
//            studentInfo.setStudent_study_length(tempStudent.getXXNX());
//            studentInfo.setStudent_schoolroll_status(tempStudent.getXJZT());
//            studentInfo.setStudent_current_grade(tempStudent.getDQSZJ());
//            studentInfo.setStudent_enroll_date(tempStudent.getRXRQ());
//            studentInfo.setStudent_tel_number(tempStudent.getLXDH());
//            studentInfo.setStudent_profession_code(tempStudent.getZYDM());
            StudentInfo exist=pullOutService.findStudentInfoByStudentId(studentInfo.getStudentSchoolId());
            if(exist!=null){
                pullOutService.insertStudentInfo(studentInfo);
                System.out.println("log:插入数据成功，本条第"+i+"条");
                i++;
            } else {
                System.out.println("log:插入数据失败,信息已存在，本条第"+i+"条");
                i++;
            }
        }
        return i+"全部完成";
    }
//    @RequestMapping(value = "/getTeacherInfoData")
//    public String GetTeacherInfoData(){
//        List<BinzhiTeacherInfo> tcs = pullinService.CopyTeacherInfoFO();
//        Iterator it = tcs.iterator();
//        TeachControlView tcv=new TeachControlView();
//        int i=1;
//        while(it.hasNext()) {
//            BinzhiTeacherInfo t= (BinzhiTeacherInfo) it.next();
//            TeacherInfo ci=new TeacherInfo();
//            ci.setTeacher_id(t.getZGH());
//            ci.setTeacher_name(t.getXM());
//            ci.setTeacher_sexual(t.getXB());
//            ci.setTeacher_birthday(t.getCSRQ());
//            ci.setTeacher_tel_number(t.getLXDH());
//            ci.setTeacher_email_address(t.getEMLDZ());
//            ci.setTeacher_college(t.getBM());
//            ci.setTeacher_position(t.getZW());
//            ci.setTeacher_title(t.getZC());
//            ci.setTeacher_education(t.getXL());
//            ci.setTeacher_research_direction(t.getJXYJFX());
//            ci.setTeacher_priority(t.getYXJ());
//            ci.setTeacher_class_distribution(t.getKSFB());
//            ci.setTeacher_profession_name(t.getZYMC());
//            ci.setTeacher_graduated_school(t.getBYYX());
//            ci.setTeacher_qualifications(t.getYWJSZG());
//            ci.setTeacher_personnel_id(t.getRSZGH());
//            ci.setTeacher_whether_external(t.getSFWP());
//            ci.setTeacher_whether_laboratory(t.getSFSYSRY());
//            ci.setTeacher_whether_on_duty(t.getSFZG());
//            ci.setTeacher_political_status(t.getZZMM());
//            ci.setTeacher_ethnic(t.getMZ());
//            ci.setTeacher_degree(t.getXW());
//            ci.setTeacher_whether_counselor(t.getSFFDY());
//            ci.setTeacher_pinyin_short(t.getJSXMPY());
//            try{
//                TeacherInfo exist=pullOutService.findTeacherInfobyTeacherId(ci.getTeacherId());
//                if(exist==null){
//                    pullOutService.insertTeacher(ci);
//                    System.out.println("log:插入数据成功，本条第"+i+"条");
//                    i++;
//                }else {
//                    System.out.println("log:插入数据失败数据已存在，本条第"+i+"条");
//                    i++;
//                }
//
//            }catch (Exception e){
//                errReason="教师信息错误原因:"+e+"\n";
//                errId="错误位置:"+i+"\n";
//                errPos="错误信息:"+t.getZGH()+"\n";
//                erresult=errReason+errId+errPos;
//                tcv.appendMethodB("errInfo.txt",erresult);
//            }
//
//        }
//        return i+"条数据全部完成";
//    }


}